<?php
	class gallery extends CI_Controller
	{
		public function __construct()
		{
			parent::__construct();
			
			$config = array(
				'upload_path'		=>	realpath(FCPATH.'uploads/gallery/images/'),
				'allowed_types'		=>	'gif|jpg|jpeg|png',
				/*'max_width'			=>	768,
				'max_height'		=>	600,*/
				'max_size'			=>	4096,
			);
			
			$this->load->library('upload',$config);
			$this->load->helper('url');
			$this->load->helper('form');
			$this->load->model('Jobs');
			$this->load->model('Flashgallery');
			
			$user =& Users::getInstance();
			if ($user->level < 1) {
				redirect('/');
			}
		}
		
		public function index()
		{
			$this->load->library('Menu');
			$menu = new Menu;
			$user =& Users::getInstance();
			$data = $menu->gen();
			$data['user'] = $user;
			$data['stats']['oncoming'] = $this->Jobs->getOncoming(-1, true);
			$data['stats']['quote'] = $this->Jobs->getNeedQuote(-1, true);
			$data['images'] = $this->Flashgallery->getImages();
			
			$this->load->view('gallery.php', $data);
		}
		
		public function upload()
		{
			if($this->upload->do_upload('userfile'))
			{
				$info = $this->upload->data();
				
				$this->Flashgallery->addImage($info['file_name'], $this->input->post('imagetext'));
			}
			else
			{
				//print '<pre>';	print_r($this->upload->data());	print '</pre>';
				//$this->load->view('admin/upload/error.php');
			}
			
			redirect('/gallery');
		}
		
		public function delete()
		{
			$image = $this->uri->rsegment(3, 0);
			$this->Flashgallery->deleteImage($image);
			redirect('/gallery');
		}
	}
?>